package com.hxx.day9;

/**
 * 单例设计模式
 * 懒汉式
 * 线程安全synchronized
 */
public class SingtonDemo {

    private SingtonDemo() {
    }
    private volatile static SingtonDemo instance = null;

    //双重检查锁:自旋锁
    public  static SingtonDemo getInstance() {
        //10000 code
        //定义同步块，锁对象为SingtonDemo.class
        synchronized (SingtonDemo.class) {
            if (instance == null) {
                instance = new SingtonDemo();
            }
        }
        return instance;
    }

}





















